package pers.feng1240.blog.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import pers.feng1240.blog.dao.BlogDao;
import pers.feng1240.blog.dao.BlogTagDao;
import pers.feng1240.blog.entities.Blog;
import pers.feng1240.blog.service.BlogService;
import pers.feng1240.blog.util.PageHelper;

/*
 * 博客业务逻辑接口实现类
 */

@Service("blogService")
public class BlogServiceImpl implements BlogService{

	@Resource
	private BlogDao blogDao;	//数据访问层
	@Resource
	private BlogTagDao blogTagDao; 
	
	@Override
	public void addObject(Object blog) {
		// TODO Auto-generated method stub
		//blogDao.addObject(blog);
	}

	/*
	 * 分页列表
	 * @param pageIndex 要获取的页码
	 * @see pers.feng1240.blog.service.AbstractService#getPageList(java.lang.String)
	 */
	public Map<String, Object> getPageList(int pageIndex) {
		Map<String,Object> mapRes = new HashMap<String,Object>();
		int count = blogDao.objectCount(); //对象总个数
		mapRes.put("count", count);
		mapRes.put("pageSize", PageHelper.pageSize(count));//页数
		mapRes.put("pageIndex", pageIndex); //
		mapRes.put("objectList", blogDao.getPageList(PageHelper.selObj(pageIndex)));
		return mapRes;

	}

	/*
	 * 列表
	 * @see pers.feng1240.blog.service.AbstractService#getObjectList()
	 */
	public List<Object> getObjectList() {
		// TODO Auto-generated method stub
		return blogDao.getObjectList();
	}
	
	/*
	 * 列表
	 * @param pageIndex 当前页
	 */
	public List<Object> getObjectList(String pageIndex) {
		// TODO Auto-generated method stub
		System.out.println(123);
		return blogDao.getObjectList();
	}

	@Override
	public Object getById(int id) {
		// TODO Auto-generated method stub
		return blogDao.getById(id);
	}

	@Override
	public void updateObject(Object blog) {
		// TODO Auto-generated method stub
		blogDao.updateObject(blog);
	}

	/*
	 * 写博客
	 * @see pers.feng1240.blog.service.BlogService#writing(pers.feng1240.blog.entities.Blog, int[])
	 */
	public void writing(Blog blog, int[] tags) {
		// TODO Auto-generated method stub
		blogDao.addObject(blog);//添加blog
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("blogId", blog.getId());
		map.put("tagId", tags);
		blogTagDao.addObject(map); //添加标签
		
	}

	/*	
	 * Description:撤销置顶
	 * @see pers.feng1240.blog.service.BlogService#unTop()
	 */
    @Override
    public void unTop() {
        blogDao.unTop(); 
    }

    /*
     * Description:设置置顶
     * @see pers.feng1240.blog.service.BlogService#setTop(java.util.Map)
     */
    @Override
    public void setTop(int id) {
        blogDao.setTop(id);
        
    }

    /*
     * Description: 博客冻结
     * @see pers.feng1240.blog.service.BlogService#setFreeze(int)
     */
    @Override
    public void setFreeze(int id) {
        blogDao.setFreeze(id);
        
    }

    /*
     * Description:博客解冻
     * @see pers.feng1240.blog.service.BlogService#setUnFreeze(int)
     */
    @Override
    public void setUnFreeze(int id) {
        blogDao.setUnFreeze(id);
        
    }

	/*
	 * 删除
	 * @see pers.feng1240.blog.service.AbstractService#deleteById(int)
	 */
	public void deleteById(int id) {
		blogDao.deleteById(id);
		
	}

}
